package com.scau.meetingbook.controller;

import com.scau.meetingbook.dto.MeetingRoomDTO;
import com.scau.meetingbook.dto.MeetingRoomsDTO;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.scau.meetingbook.service.MeetingRoomsService;
import com.scau.meetingbook.pojo.MeetingRooms;
import com.scau.meetingbook.vo.ResultVO;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/meetingRooms")
public class MeetingRoomsController {

    @Autowired
    private MeetingRoomsService meetingRoomsService;

    /**
     * 查询空闲会议室
     * @return
     */
    @GetMapping("/getMeetingRooms")
    @ApiOperation(value = "查询空闲会议室")
    public ResultVO<List<MeetingRoomsDTO>> getMeetingRooms(@RequestParam Date date,
                                                           @RequestParam String startTime,
                                                           @RequestParam String endTime,
                                                           @RequestParam Integer personNum,
                                                           @RequestParam String type,
                                                           @RequestParam(name = "equipmentIds", required = false) ArrayList<Integer> equipmentIds) throws Exception {
        return meetingRoomsService.getMeetingRooms(date,startTime, endTime, personNum, type, equipmentIds);
    }






    @GetMapping("/getMeetingRoomsById")
    public ResultVO<MeetingRooms> getMeetingRoomsById(Integer id) throws Exception {
        return meetingRoomsService.getMeetingRoomsById(id);
    }


    @DeleteMapping("/deleteMeetingRoomsById")
    public ResultVO deleteMeetingRoomsById(Integer id) throws Exception {
        return meetingRoomsService.deleteMeetingRoomsById(id);
    }

    @GetMapping("/getAllMeetingRoomsStatus")
    public ResultVO<List<MeetingRooms>> getAllMeetingRoomsStatus() {
        return meetingRoomsService.getAllMeetingRoomsStatus();
    }
    @PutMapping("/changeMeetingRoomsStatus")
    public ResultVO changeMeetingRoomsStatus(Integer roomId, String status) {
        return meetingRoomsService.changeMeetingRoomsStatus(roomId,status);
    }

    // 新增会议室
    @PostMapping
    public ResultVO addMeetingRoom(@RequestBody MeetingRoomDTO meetingRoomDTO) {
        return meetingRoomsService.insertMeetingRooms(meetingRoomDTO);
    }

    // 修改会议室
    @PutMapping("/{id}")
    public ResultVO updateMeetingRoom(@PathVariable Integer id, @RequestBody MeetingRoomDTO meetingRoomDTO) {
        meetingRoomDTO.setRoomId(id);
        return meetingRoomsService.updateMeetingRoomsById(meetingRoomDTO);
    }

    // 删除会议室
    @DeleteMapping("/{id}")
    public ResultVO deleteMeetingRoom(@PathVariable Integer id) throws Exception {
        return meetingRoomsService.deleteMeetingRoomsById(id);
    }

    // 修改租赁价格
    @PatchMapping("/{id}/price")
    public ResultVO updateRentalPrice(@PathVariable Integer id, @RequestParam BigDecimal price) {
        MeetingRooms meetingRoom = new MeetingRooms();
        meetingRoom.setRoomId(id);
        meetingRoom.setHourlyRentalPrice(price);
        boolean result = meetingRoomsService.updateById(meetingRoom);
        return result ? ResultVO.success("价格更新成功") : ResultVO.fail("价格更新失败");
    }

    @GetMapping("/getAllMeetingRooms")
    public ResultVO<List<MeetingRoomsDTO>> getAllMeetingRooms() {
        return meetingRoomsService.getAllMeetingRooms();
    }
}